﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using jiaju.Models.DBModel;
using jiaju.Models;
namespace jiaju.Areas.Back.Models.DAL
{
    public class HomeInfoService
    {
        public static HomeInfo GetList()
        {
            string sql = "select * from dbo.HomeInfo";
            SqlDataReader sdr = DBHelp.ExecuteReader(sql);
            HomeInfo hom = null;
            while (sdr.Read())
            {
                int Id = (int)sdr["Id"];
                string JieShao = (string)sdr["JieShao"];
                string ZsTel = (string)sdr["ZsTel"];
                string LxTel = (string)sdr["LxTel"];
                string Email = (string)sdr["Email"];
                string Info = (string)sdr["Info"];
                string Address = (string)sdr["Address"];
                string WenHua = (string)sdr["WenHua"];
                string X = (string)sdr["X"];
                string Y = (string)sdr["Y"];
                hom = new HomeInfo()
                {
                    Id = Id,
                    JieShao =JieShao,
                    ZsTel=ZsTel,
                    LxTel=LxTel,
                    Email = Email,
                    Info = Info,
                    Address=Address,
                    WenHua = WenHua,
                    X = X,
                    Y = Y
                };
            }
            return hom;
        }
        public static int EditList(HomeInfo hom)
        {
            string sql = string.Format(@"UPDATE [dbo].[HomeInfo]
                                       SET [JieShao] = '{0}',[ZsTel] = '{1}',[LxTel] = '{2}',[Email] = '{3}',[Info] = '{4}',[Address] = '{5}',[WenHua] = '{6}',[X] = '{7}',[Y] = '{8}'WHERE Id={9}",
                                       hom.JieShao, hom.ZsTel, hom.LxTel, hom.Email, hom.Info, hom.Address, hom.WenHua, hom.X, hom.Y, hom.Id);
            int num = DBHelp.ExecuteNonQuery(sql);
            return num;
        }
    }
}